# NOTE: only 1 of this reducer should exist

import sys
import math

def main():
    '''
    output: mi_model.txt
    (c, k).., (cc, k).. -> (cc, mutual infomation value)..
        all in memory calculation
    '''
    pc1 = {}
    pc2 = {}
    for line in sys.stdin:
        c, v = line.split()
        v = int(v)

        if len(c) == 1:
            pc1[c] = pc1.get(c, 0) + v
        elif len(c) == 2:
            pc2[c] = pc2.get(c, 0) + v

    norm1 = sum(pc1.values()) * 1.0
    norm2 = sum(pc2.values()) * 1.0

    for c in pc1:
        pc1[c] = math.log(pc1[c] / norm1, 2.0)

    for c in pc2:
        pc2[c] = math.log(pc2[c] / norm2, 2.0)

    for a, b in pc2:
        pc2[a + b] = pc2[a + b] - pc1[a] - pc1[b]

    for c, v in pc2.items():
        print '%s\t%s' % (c, v.hex())

if __name__ == '__main__':
    main()
